﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SeaBattle.Domain.Abstract;
using SeaBattle.Domain.Entities;

namespace SeaBattle.Domain.Concrete
{
    public class FakeShipRepository : IShipRepository
    {
        private static List<Ship> ships = new List<Ship>();

        /// <summary>
        /// Gets the ship.
        /// </summary>
        /// <param name="id">The ship's id.</param>
        /// <returns></returns>
        public Ship GetShip(int id)
        {
            return ships.FirstOrDefault(x => x.Id == id);
        }

        /// <summary>
        /// Creates a ship. (Add a new ship instanse to the storage)
        /// </summary>
        /// <param name="partsCount">Count of the ship's parts.</param>
        /// <returns></returns>
        public Ship CreateShip(int x, int y, byte partsCount)
        {
            var ship = new Ship(x, y, partsCount) {Id = ships.Count + 1};
            ships.Add(ship);
            return ship;
        }

        /// <summary>
        /// Saves the ship.
        /// </summary>
        /// <param name="ship"></param>
        /// <returns></returns>
        public Ship SaveShip(Ship ship)
        {
            return ship;
        }
        
        public void RemoveShip(Ship ship)
        {
            ships.Remove(ship);
        }
    }
}
